#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

vector<pair<string,int> > ret;
void sb(string& s){
    reverse(s.begin(),s.end());
    string ss;
    for(int i = 0;i < s.size() && i < 20;i++){
        if(s[i] >= 'a' && s[i] <= 'z' || s[i] >= '0' && s[i] <= '9' || s[i] == ' '){
            ss += s[i];
        }else{
            break;
        }
    }
    reverse(ss.begin(),ss.end());
 //   cout<<ss<<endl;
    for(pair<string,int>& kv : ret){
        if(kv.first == ss){
            kv.second++;
            return;
        }
    }
    ret.push_back({ss,1});
}

int main(){
    string s;
    while(getline(cin,s)){
        sb(s);
    }
    int i = 0;
    if(ret.size() > 8){
        i = ret.size() - 8;
    }
    for(;i < ret.size();i++){
        cout<<ret[i].first<<" "<<ret[i].second<<endl;
    }
    return 0;
}
